package spade;

import java.util.Vector;

public class AID
{
	String	       name	      = null;
	Vector<String>	addresses	= new Vector<String>();
	Vector<String>	resolvers	= new Vector<String>();

	public AID(String name, Vector<String> addresses)
	{
		this.name = name;
		this.addresses = addresses;
	}
	public AID()
	{
		this(null, null);
	}
	public AID(String name) {
		Vector<String> v = new Vector<String>();
		v.add(name);
		this.name = name;
		this.addresses = v;
	}
	public Vector<String> getAddresses()
	{
		return addresses;
	}
	public void setAddresses(Vector<String> addresses)
	{
		this.addresses = addresses;
	}
	public void addAddress(String addr)
	{
		this.addresses.add(addr);
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public Vector<String> getResolvers()
	{
		return resolvers;
	}
	public void setResolvers(Vector<String> resolvers)
	{
		this.resolvers = resolvers;
	}
	public void addResolver(String res)
	{
		this.resolvers.add(res);
	}
	public boolean equals(Object o)
	{
		if (o == null)
			return false;
		else if (o instanceof AID == false)
			return false;
		else if (this.name == null)
			return false;
		else
		{
			// Collections.sort(this.addresses);
			// Collections.sort(((AID)o).addresses);
			if (Util.equalsLists(this.addresses, ((AID) o).addresses) == false)
				return false;
			else
				return true;
		}
	}
	private String encodeTag(String tag, String content)
	{
		String sb = "<" + tag + ">" + content + "</" + tag + ">";
		return sb;
	}
	public String asXML()
	{
		String sb =
		        "<agent-identifier>\n\t" + encodeTag("name", this.name) + "\n";
		sb += "\t<addresses>\n";

		for (int i = 0; i < this.addresses.size(); i++)
		{
			String addr = this.addresses.get(i);
			sb += "\t\t" + encodeTag("url", addr) + "\n";
		}

		sb += "\t</addresses>\n";
		sb += "</agent-identifier>\n";

		return sb;
	}
	public String toString()
	{
		return asXML();
	}

}
